import type { AxiosResponse } from "node_modules/axios/index.d.cts"
import type * as SimEngine from "./type"
import { request } from "@/http/axios"

const baseURL = import.meta.env.VITE_TRAIN_API

/** 增 */
export function createSimEngineDataApi(data: FormData) {
  return request({
    baseURL,
    headers: {
      "Content-Type": "multipart/form-data"
    },
    url: "/toksim/resource/sim_engine/add",
    method: "post",
    data
  })
}

/** 删 */
export function deleteSimEngineDataApi(sim_engine_ids: string[]) {
  return request({
    baseURL,
    url: `/toksim/resource/sim_engine/delete`,
    method: "post",
    data: {
      sim_engine_ids
    }
  })
}

/** 改 */
export function updateSimEngineDataApi(data: FormData) {
  return request({
    baseURL,
    headers: {
      "Content-Type": "multipart/form-data"
    },
    url: "/toksim/resource/sim_engine/edit",
    method: "post",
    data
  })
}

/** 查 */
export function getSimEngineDataApi(params: SimEngine.PageTableRequestData) {
  return request<SimEngine.SearchSimEngineTableResponseData>({
    baseURL,
    url: "/toksim/resource/sim_engine/search",
    method: "post",
    data: params
  })
}

/** 根据id查询资源库信息 */
export function getSimEngineInfoApi(id: string) {
  return request<SimEngine.SimEngineViewInfoResponseData>({
    baseURL,
    url: `/toksim/resource/sim_engine/get/${id}`,
    method: "get"
  })
}
/** 根据引擎id查询工程目录 */
export function getSimEngineProjectDirApi(params: any) {
  return request<any>({
    baseURL,
    url: `/toksim/resource/sim_engine_file/get`,
    method: "get",
    params
  })
}
/** 根据引擎文件id查询工程文件内容 */
export function getSimEngineProjectContentApi(file_id: string) {
  return request<any>({
    baseURL,
    url: `/toksim/resource/sim_engine_file/content/get/${file_id}`,
    method: "get"
  })
}
/** 更新引擎文件内容 */
export function saveSimFile(data: FormData) {
  return request<ApiResponseData<undefined>>({
    baseURL,
    headers: {
      "Content-Type": "multipart/form-data"
    },
    url: "/toksim/resource/sim_engine_file/update_code",
    method: "post",
    data
  })
}
/** 文件目录重命名 */
export function engineFileRenameApi(data:any) {
  return request({
    baseURL,
    url: `/toksim/resource/sim_engine_file/rename`,
    method: "post",
    data
  })
}
/** 增 引擎文件 */
export function addSimEngineFileApi(data: any) {
  return request({
    baseURL,
    url: `/toksim/resource/sim_engine_file/add`,
    method: "post",
    data
  })
}
/** 删 引擎文件 */
export function deleteSimEngineFileApi(ids: string[]) {
  return request({
    baseURL,
    url: `/toksim/resource/sim_engine_file/delete`,
    method: "post",
    data: {
      ids
    }
  })
}
/** 移动 引擎文件 */
export function moveSimEngineFileApi(data: any) {
  return request({
    baseURL,
    url: `/toksim/resource/sim_engine_file/move`,
    method: "post",
    data
  })
}
/** 复制 引擎文件 */
export function copySimEngineFileApi(data: any) {
  return request({
    baseURL,
    url: `/toksim/resource/sim_engine_file/copy`,
    method: "post",
    data
  })
}
/** 更换主文件 */
export function updateFileMainApi(id: string) {
  return request({
    baseURL,
    url: `/toksim/resource/sim_engine_file/update_main/${id}`,
    method: "post"
  })
}
/** 获取引擎类型 */
export function getSimEngineTypeOptionsApi() {
  return request<ApiResponseData<{ type: string[] }>>({
    baseURL,
    url: `/toksim/resource/sim_engine/type/get`,
    method: "get"
  })
}

/** 下载引擎资源 */
export function downloadSimEngineApi(data: any) {
  return request<AxiosResponse>({
    baseURL,
    headers: {
      "Content-Type": "application/octet-stream"
    },
    responseType: "blob",
    url: `toksim/resource/sim_engine/download_document`,
    method: "post",
    data
  })
}

/** 获取操作系统类型 */
export function getSimEngineOSOptionsApi() {
  return request<ApiResponseData<{ os: string[] }>>({
    baseURL,
    url: `/toksim/resource/sim_engine/os/get`,
    method: "get"
  })
}

/** 获取引擎 */
export function getSimEngineOptionsApi() {
  return request<SimEngine.SimEngineListResponseData>({
    baseURL,
    url: `/toksim/resource/sim_engine/list`,
    method: "get"
  })
}


/** 获取wiki文件数据 */
export function getAssociateOptionsApi(associate_id: string) {
  return request({
    baseURL,
    url: `/toksim/resource/document/associate/get/${associate_id}`,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
    },
    method: "get"
  })
}